package com.moonshineproject.plugin.syntax
{
	import com.moonshineproject.GlobalEventDispatcher;
	import com.moonshineproject.parser.AS3LineParser;
	import com.moonshineproject.plugin.IEditorPlugin;
	import com.moonshineproject.plugin.IMenuPlugin;
	import com.moonshineproject.plugin.IPlugin;
	import com.moonshineproject.plugin.PluginBase;
	import com.moonshineproject.events.EditorPluginEvent;
	import com.moonshineproject.plugin.menu.MenuPlugin;
	import com.moonshineproject.plugin.menu.vo.MenuItem;
	import com.moonshineproject.plugin.settings.ISettingsProvider;
	import com.moonshineproject.plugin.settings.vo.ISetting;
	import com.moonshineproject.vo.Settings;
	
	import flash.events.Event;
	import flash.text.engine.ElementFormat;
	import flash.text.engine.FontDescription;
	
	public class AS3SyntaxPlugin extends PluginBase implements  ISettingsProvider, IEditorPlugin
	{
		private var formats:Object = {};
		
		override public function get name():String 			{return "AS3 Syntax Plugin";}
		override public function get author():String 		{return "Moonshine Project Team";}
		override public function get description():String 	{return "Provides highlighting for AS3.";}
		public function getSettingsList():Vector.<ISetting>		{return new Vector.<ISetting>();}
		
		
		override public function activate():void
		{ 
			super.activate();
			init();
		}
		
		private function init():void
		{
			var fontDescription:FontDescription = Settings.font.defaultFontDescription;
			var fontSize:Number = Settings.font.defaultFontSize;
			
			formats[0] = /* default, parser fault */			new ElementFormat(fontDescription, fontSize, 0xFF0000);
			formats[AS3LineParser.AS_CODE] =					new ElementFormat(fontDescription, fontSize, 0x101010);
			formats[AS3LineParser.AS_STRING1] = 				
			formats[AS3LineParser.AS_STRING2] = 				new ElementFormat(fontDescription, fontSize, 0xca2323);
			formats[AS3LineParser.AS_COMMENT] =					 
			formats[AS3LineParser.AS_MULTILINE_COMMENT] = 		new ElementFormat(fontDescription, fontSize, 0x39c02f);
			formats[AS3LineParser.AS_REGULAR_EXPRESSION] = 		new ElementFormat(fontDescription, fontSize, 0x9b0000);
			formats[AS3LineParser.AS_KEYWORD] = 				new ElementFormat(fontDescription, fontSize, 0x0082cd);
			formats[AS3LineParser.AS_VAR_KEYWORD] =				new ElementFormat(fontDescription, fontSize, 0x6d5a9c);
			formats[AS3LineParser.AS_FUNCTION_KEYWORD] =		new ElementFormat(fontDescription, fontSize, 0x3382dd);
			formats[AS3LineParser.AS_PACKAGE_CLASS_KEYWORDS] = 	new ElementFormat(fontDescription, fontSize, 0xa848da);
			formats['lineNumber'] =								new ElementFormat(fontDescription, fontSize, 0x888888);
			formats['breakPointLineNumber'] =					new ElementFormat(fontDescription, fontSize, 0xffffff);
			formats['breakPointBackground'] =					0xdea5dd;
			
			dispatcher.addEventListener(EditorPluginEvent.EVENT_EDITOR_OPEN, handleEditorOpen);
		}
		
		private function handleEditorOpen(event:EditorPluginEvent):void
		{
			if (event.fileExtension == "as")
			{
				event.editor.setParserAndStyles(new AS3LineParser(), formats);
			}
		}
		
	}
}